Crate globwalk [−] [src]
Recursively find files in a directory using globs.
Features include
gitignore
's extended glob syntax- Control over symlink behavior
- Control depth walked
- Control order results are returned
Examples
Finding image files in the current directory.
extern crate globwalk; use std::fs; for img in globwalk::glob("*.{png,jpg,gif}").unwrap() { if let Ok(img) = img { fs::remove_file(img.path()).unwrap(); } }
Tweak walk options
extern crate globwalk; use std::fs; let walker = globwalk::glob("*.{png,jpg,gif}") .unwrap() .max_depth(4) .follow_links(true) .into_iter() .filter_map(Result::ok); for img in walker { fs::remove_file(img.path()).unwrap(); }
Advanced Globbing
By using one of the constructors of globwalk::GlobWalker
, it is possible to alter the
base-directory or add multiple patterns.
extern crate globwalk; use std::fs; let walker = globwalk::GlobWalker::from_patterns(BASE_DIR, &["*.{png,jpg,gif}", "!Pictures/*"]) .unwrap() .into_iter() .filter_map(Result::ok); for img in walker { fs::remove_file(img.path()).unwrap(); }
Structs
GlobWalker |
An iterator for recursively yielding glob matches. |
IntoIter |
An iterator which emits glob-matched patterns. |
Functions
glob |
Construct a new |
Type Definitions
GlobError |
Error from parsing globs. |
WalkError |
Error from iterating on files. |